package edu.wtbu.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import edu.wtbu.service.ScheduleService;

@Controller
@ResponseBody
public class ScheduleController {

	@Resource
	private ScheduleService scheduleService;

	@RequestMapping("/updateSchedule")
	public Object updateSchedule(int scheduleId,String status) {
		return scheduleService.updateSchedule(scheduleId, status);
	}
	
	@RequestMapping("/getFlightStatus")
	public Object  getFlightStatus(String departureDate, String startPage, String pageSize){
		
		int start =0;
		try {
			start = Integer.parseInt(startPage);
		}catch (Exception e) {
			start =1;
		}
		int size =0;
		try {
			size = Integer.parseInt(pageSize);
		}catch (Exception e) {
			size =10;
		}
		return scheduleService.getFlightStatus(departureDate, start, size);
	}
	@RequestMapping("/getSchedule")
	public Object  findScheduleByCityAndDate(String fromCity, String toCity, String startDate, String endDate){
		
		return scheduleService.findScheduleByCityAndDate(fromCity, toCity, startDate, endDate);
	}
	@RequestMapping("/getScheduleDetail")
	public Object  getScheduleDetail(String scheduleId){
		int sId =0;
		try {
			sId = Integer.parseInt(scheduleId);
		}catch (Exception e) {
			sId =0;
		}
		return scheduleService.getScheduleDetail(sId);
	}
	@RequestMapping("/getSearchFlight")
	public Object  findNonStopScheduleList(String fromCity, String toCity, String departureDate, String cabinTypeId,
			String flightType) {
		int cId =0;
		try {
			cId = Integer.parseInt(cabinTypeId);
		}catch (Exception e) {
			cId =1;
		}
		return scheduleService.findNonStopScheduleList(fromCity, toCity, departureDate, cId, flightType);
	}
}
